package com.ljpz.cart.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ljpz.common.service.ApiService;
import com.ljpz.cart.bean.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * Created by liujunchen on 2017/1/4.
 */
@Service
public class ItemService {
    @Autowired
    private ApiService apiService   ;
    @Value("${LJPZ_MANAGE_URL}")
    private  String  LJPZ_MANAGE_URL   ;
    private  static  final  ObjectMapper  MAPPER=new ObjectMapper()  ;
    public Item queryById(Long itemId){
        try {
            String url=LJPZ_MANAGE_URL+"/rest/api/item/"+itemId;
            String   jsonData= this.apiService.doGet(url)  ;
            if (org.apache.commons.lang3.StringUtils.isNotEmpty(jsonData)){
                return  MAPPER.readValue(jsonData,Item.class)   ;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null ;
    }

}
